<?php
/**
* Handles all log-generation and querying for system-wide events.
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
use Buan\Model;
class LogManager extends ScribbleModelManager {

	/**
	* Type for uncategorized log messages.
	*
	* @var int
	*/
	const GENERAL = 0;

	/**
	* Informational message.
	*
	* @constant int
	*/
	const INFO = 1;

	/**
	* Error.
	*
	* @constant int
	*/
	const ERROR = 2;

	/**
	* User's specific action.
	*
	* @constant int
	*/
	const USER_ACTION = 4;

	/**
	* Add a new log message.
	* Returns the LogModel instance that was created.
	*
	* @param string Log message
	* @param int Type of message
	* @param string User identifier
	* @param string Parent Log model
	* @return LogModel
	*/
	static public function add($msg, $type=self::GENERAL, $uid='', $parentId='') {
		$log = Model::create('Log');
		$log->log_id = $parentId;
		$log->message = $msg;
		$log->type = $type;
		$log->user_id = $uid;
		$log->datecreated = time();
		$log->getModelManager()->save($log);
		return $log;
	}
}
?>